import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import { URL, fileURLToPath } from 'node:url';
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
import UnoCSS from 'unocss/vite';
import MotionResolver from 'motion-v/resolver';
// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      dts: true,
      resolvers: [ElementPlusResolver()],
    }),
    UnoCSS(),
    Components({
      dts: true, // 生成类型声明文件
      resolvers: [MotionResolver(), ElementPlusResolver()],
    }),
  ],
  build: {
    // 生产环境配置
    minify: 'terser', // 指定使用 terser 作为代码压缩工具
    terserOptions: {
      compress: {
        // 移除 console
        drop_console: true, // 在压缩代码时移除所有 console 语句
        drop_debugger: true, // 在压缩代码时移除所有 debugger 语句
      },
    },
  },
  server: {
    open: true,
    host: '0.0.0.0',
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `@use "@/styles/variables" as *;`,
      },
    },
  },
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
    },
  },
});
